//
//  ViewController.m
//  AutoLayoutTest
//
//  Created by wangrui on 14-2-24.
//  Copyright (c) 2014年 PPS. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    //[self testBasicLayout];
}

- (void)testBasicLayout{
    UIView *aView = [[UIView alloc] init];
    aView.backgroundColor = [UIColor redColor];
    [aView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addSubview:aView];
    
    UIView *bView = [[UIView alloc] init];
    bView.backgroundColor = [UIColor blueColor];
    [bView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addSubview:bView];
    
    NSDictionary *views = NSDictionaryOfVariableBindings(aView, bView);
    
    [self.view addConstraints:
     [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(>=100)-[aView(100)]"
                                             options:0
                                             metrics:nil
                                               views:views]];
    
    [self.view addConstraints:
     [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(100)-[aView(50)]-(100)-|"
                                             options:0
                                             metrics:nil
                                               views:views]];
    
    [self.view addConstraints:
     [NSLayoutConstraint constraintsWithVisualFormat:@"H:[bView(==aView)]"
                                             options:0
                                             metrics:nil
                                               views:views]];
    [self.view addConstraints:
     [NSLayoutConstraint constraintsWithVisualFormat:@"V:[bView(==aView)]"
                                             options:0
                                             metrics:nil
                                               views:views]];
    
    [self.view addConstraint:
     [NSLayoutConstraint constraintWithItem:bView
                                  attribute:NSLayoutAttributeLeft
                                  relatedBy:NSLayoutRelationEqual
                                     toItem:aView
                                  attribute:NSLayoutAttributeRight
                                 multiplier:1
                                   constant:10]];
    
    [self.view addConstraint:
     [NSLayoutConstraint constraintWithItem:bView
                                  attribute:NSLayoutAttributeTop
                                  relatedBy:NSLayoutRelationEqual
                                     toItem:aView
                                  attribute:NSLayoutAttributeTop
                                 multiplier:1
                                   constant:0]];

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
